package com.kuangstudy.collection.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * ClassName: UnsafeBuyTicket
 * date: 2021/07/13 17:26:53
 *Map接口的使用
 * 特点 存储键值对 键不能重复 值能重复 无序
 * @author zlk
 */
public class Demo1 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("cn","中国");
        map.put("uk","英国");
        map.put("usa","美国");
        System.out.println(map.size());
        System.out.println(map.toString());
//        map.remove("cn");
        System.out.println(map.toString());
        /*遍历 keySet存储的是key的set集合*/
        Set<String> strings = map.keySet();
        for (String string : strings) {
            System.out.println(string + "=>" + map.get(string));
        }
        /*使用entrySet遍历 效率比上面的高*/
        for (Map.Entry<String, String> stringStringEntry : map.entrySet()) {
            System.out.println(stringStringEntry.getKey()+"=>"+stringStringEntry.getValue());
        }
        /*判断*/
        System.out.println(map.containsKey("cn"));
        System.out.println(map.containsValue("中国"));

    }
}
